var configs = {
	headerH: '44px',
	navH: "50px",
	AppName: '颜值同城交友',
	manager_id: 777,
	user_id: '',
	device: plus.os.name == 'iOS' ? 1 : 0
}
var user_info;
var info = plus.storage.getItem("user_info");
if(info) {
	user_info = JSON.parse(info);
	configs.user_id = user_info.user_id;
}
plus.webview.currentWebview().setStyle({
	scrollIndicator: 'none'
});
var functionclass = {
	getnet: function() {
		if(window.plus && plus.networkinfo.getCurrentType() === plus.networkinfo.CONNECTION_NONE) {
			return false;
		} else {
			return true;
		}
	},
	shuffle: function(arr) {

		var i = arr.length,
			t, j;
		while(i) {
			j = Math.floor(Math.random() * i--);
			t = arr[i];
			arr[i] = arr[j];
			arr[j] = t;
		}

		return arr;
	},
	shuffle2: function(arr) {
		var i = arr.length,
			t, j;
		while(i) {
			j = Math.floor(Math.random() * i--);
			t = arr[i];
			arr[i] = arr[j];
			arr[j] = t;
		}
	}
}

function MD5Entry(user_id, device) {
	var myDate = new Date();
	var year = myDate.getFullYear();
	var mon = myDate.getMonth() + 1;
	if(mon < 10) {
		mon = '0' + mon
	}
	var day = myDate.getDate();
	if(day < 10) {
		day = '0' + day
	}
	var date = year.toString() + mon + day;
	var str = user_id.toString() + md5(date) + device.toString();
	return md5(str)
}

function getApiUrl(siteurl, interface) {

	var n = (siteurl.split('/')).length - 1;
	if(n > 2) {
		siteurl = siteurl.substr(0, siteurl.length - 1)
	}
	var url = siteurl + '/index.php/index/' + interface + '?device=' + configs.device;
	if(configs.user_id > 0) {
		url += '&user_id=' + configs.user_id + '&token=' + MD5Entry(configs.user_id, configs.device)
	}
	return url + '&manager_id=' + configs.manager_id;
}
var WebId_Blog;

function openPersonalBlog(uid, headimg, nickname) {
	if(!uid) {
		return;
	}
	if(!WebId_Blog) {
		WebId_Blog = plus.webview.getWebviewById('Personal_Blog')
	};
	mui.fire(WebId_Blog, 'PersonalBlog', {
		uid: uid,
		headimg: headimg,
		nick_name: nickname
	});
	WebId_Blog.setStyle({
		"titleNView": {
			"titleText": nickname
		}
	});
	//	WebId_Blog.show();
	mui.openWindow({
		url: 'html/Personal_Blog.html',
		id: 'Personal_Blog'
	})
}

function clickButton() {
	if(!WebId_Blog) {
		WebId_Blog = plus.webview.getWebviewById('Personal_Blog')
	};
	mui.fire(WebId_Blog, 'jubao')
}

function isallpay() {
	var allpay = localStorage.getItem('allpay');
	if(allpay == 1) {
		return true
	} else {
		return false
	}
}

function isvipcoin(e) {
	if(e) {
		var timestamp = (Date.parse(new Date())) / 1000;
		if(user_info.vip > timestamp) {
			var date = new Date(user_info.vip * 1000);
			var y = date.getFullYear();
			var m = date.getMonth() + 1;
			var d = date.getDate();
			var t = y + '年' + m + '月' + d + '日 到期 ';
			return t
		} else {
			return '未开通会员'
		}
	} else {
		var timestamp = (Date.parse(new Date())) / 1000;
		if(user_info.vip < timestamp) {
			return false
		} else {
			return true
		}
	}
}

function islahei(uid) {
	var lahei = plus.storage.getItem('LaHeiData');
	var lahei_Data = [];
	if(lahei) {
		lahei_Data = JSON.parse(lahei);
		if(lahei_Data.length > 0) {
			var kty;
			mui.each(lahei_Data, function(key, value) {
				if(value == uid) {
					kty = true;
					return false;
				}
			})
			if(kty) {
				return true;
			}
		}
	} else {
		return false;
	}
}

function showWaiting(value, ml) {
	if(ml == undefined) {
		ml = "";
	}
	plus.nativeUI.showWaiting(value, {
		width: '150px',
		height: '150px',
		color: '#fff',
		size: '20px',
		textalign: 'center',
		padlock: true,
		loading: ({
			display: 'block',
			icon: ml + 'img/function/loading.png',
			height: '80px',
			interval: 120
		})
	});

}

function logindata(data, type) {
	plus.storage.setItem('user_info', JSON.stringify(data));
	if(type == 'login') {
		mui.openWindow({
			url: "ParentFrame.html",
			id: 'ParentFrame',
		})
	}
}

function openWallet(walletURL, type) {
	mui.openWindow({
		url: walletURL,
		id: 'wallet',
		styles: {
			titleNView: {
				titleText: "充值",
				titleColor: "#FFF",
				titleSize: "20px",
				backgroundColor: "#fd698d",
				splitLine: {
					color: "#CCCCCC",
					height: "1px" //
				},
				autoBackButton: true,
				buttons: [{
					text: '记录',
					float: 'right',
					fontSize: '16px',
					onclick: jiaoyijilu
				}]
			}
		},
		extras: {
			type: type
		},
		show: {
			autoShow: true,
			aniShow: "slide-in-bottom",
			event: 'titleUpdate',
		}
	});

	function jiaoyijilu() {
		var successURL = walletURL.replace('wallet', 'success');
		mui.openWindow({
			url: successURL,
			id: 'success',
			styles: {
				titleNView: {
					titleText: "充值记录",
					titleColor: "#FFF",
					titleSize: "20px",
					backgroundColor: "#fd698d",
					splitLine: {
						color: "#CCCCCC",
						height: "1px" //
					},
					autoBackButton: true
				}
			},
			extras: {
				type: 'qianbao'
			}
		});
	}
}
var masks;

function showTanChuang(tkcontent, tkleft, tkright, type, walletURL) {
	masks = mui.createMask(callback);
	masks.show();
	//	var htmls = '<div class="tankuang" id="tankuang"><div class="wenzi" id="wenzi">'+tkcontent+'</div><button class="shengji" id="zuobutton">'+tkleft+'</button><button class="nono" id="youbutton">'+tkright+'</button></div>';
	var htmls = '<div class="ts_kuang"><div class="ts_wenzi"><div class="ts_duohang">' + tkcontent + '</div></div><div class="tsk_divs"><button class="tsk_zuodiv">' + tkleft + '</button><button class="tsk_youdiv">' + tkright + '</button></div></div>';
	document.getElementById('showTanChuang').innerHTML = htmls;
	mui('.ts_kuang').on('tap', '.tsk_youdiv', function() {
		masks.close();
		document.getElementById('showTanChuang').innerHTML = '';
	})
	mui('.ts_kuang').on('tap', '.tsk_zuodiv', function() {
		openWallet(walletURL, type)
		masks.close();
		document.getElementById('showTanChuang').innerHTML = '';
	})

	function callback() {
		document.getElementById('showTanChuang').innerHTML = '';
	}
}